"""
命名空间：
    tns:"http://service.jgmes.com"
过站口：NewSaveBluetoothTestData
输入：NewSaveBluetoothTestDataRequest
    消息格式：
    tns:NewSaveBluetoothTestData
        barCode:string                  # 产品SN号
        BTTestData:string               # 不良用例序号--数字
        TestResults:string              # 测试结果--'pass' or 'fail'
        orderStationId:string           # 工站ID
输出：NewSaveBluetoothTestDataResponse
    消息格式：
    tns:NewSaveBluetoothTestDataResponse
        out:            # 格式：tns:ResultBoolean
            data:bool           # 过站成功为True
            errorCode:int       # 错误代码，暂时没见过
            isSuccess:bool      # 过站成功为True
            message:str         # 过站失败，会返回原因。过站成功，则无返回值。


返回值（固定模版）：
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <ns1:NewSaveBluetoothTestDataResponse xmlns:ns1="http://service.jgmes.com">
            <ns1:out>
                <data xmlns="http://service.jgmes.com">false</data>
                <errorCode xmlns="http://service.jgmes.com" xsi:nil="true" />
                <isSuccess xmlns="http://service.jgmes.com">false</isSuccess>
                <message xmlns="http://service.jgmes.com">本工序已扫，请检查！已做到第[4]工序[VX989-成品全功能测试站（ATS）]</message>
            </ns1:out>
        </ns1:NewSaveBluetoothTestDataResponse>
    </soap:Body>
</soap:Envelope>
"""

import requests
import re
import xml.etree.ElementTree as ET

url = 'http://192.168.0.7:8080//services/GZJDDeviceService'

headers = {
    'Content-Type':'text/xml'
}

# barCode = 'VG0015-BO0200349'
barCode = "5PDPYYY01ZA501843180038"
BTTestData = ""
TestResults = 'fail'
orderStationId = '2'
body = f'''
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                 xmlns:ser="http://service.jgmes.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:NewSaveBluetoothTestData>
         <barCode>{barCode}</barCode>
         <BTTestData>{BTTestData}</BTTestData> 
         <TestResults>{TestResults}</TestResults> 
         <orderStationId>{orderStationId}</orderStationId> 
      </ser:NewSaveBluetoothTestData>
   </soapenv:Body>
</soapenv:Envelope>
'''

res = requests.post(url,headers=headers,data=body)
print(res.status_code)
print(res.text)


